var arg = arguments[0];

function adicionar(event) {

	var quarto = {
		detalheQuarto : $.textArea.value,
		preco : $.preco.value,
		imovel : arg
	};
	
	console.log(quarto);
	
	var xhr = Ti.Network.createHTTPClient({
		onload : function() {
			console.log('ENTREI');
			var obj = JSON.parse(this.responseText);
			
			closeWindow();
		},
		onerror : function(e) {
			Ti.API.debug(e.error);
			alert('error');
		},
		timeout : 100000 // in milliseconds
	});
	xhr.open('POST', ip + "/server/rest/quarto/inserirQuarto");
	xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8");
	//Define o encoding.
	xhr.send(JSON.stringify(quarto));

	closeWindow();
}

function closeWindow() {
	$.adicionarQuartoDetalhe.close();
}